// Description: 描述
package xcache

import (
	"bytes"
	"encoding/json"
	"fmt"

	"github.com/zeromicro/go-zero/core/stringx"
)

var replacer = stringx.NewReplacer(map[string]string{
	`{"`: "#",
	`":`: "#",
	`,"`: "#",
	`"}`: "#",
	`"`:  "#",
})

// 组装列表数据的缓存key
func ComposeLcKey(prefix string, p ...interface{}) string {
	if len(p) > 0 {
		key := bytes.Buffer{}
		for _, v := range p {
			b, _ := json.Marshal(v)
			key.Write(b)
			key.WriteString("#")
		}
		return fmt.Sprintf("%s#%s", prefix, replacer.Replace(key.String()))
	}
	return prefix
}
